﻿#include "FITKAbaBoundaryConditionManager.h"
#include "FITKAbaAbstractBoundaryCondition.h"


void Interface::FITKAbaBoundaryConditionManager::deleteStepBoundaryConditions(int stepId)
{
    QList<FITKAbaAbstractBoundaryCondition*> bdsToDelete{};
    int count = this->getDataCount();
    for (int i = 0; i< count; ++i)
    {
        FITKAbstractBC* bc = this->getDataByIndex(i);
        FITKAbaAbstractBoundaryCondition* c = dynamic_cast<FITKAbaAbstractBoundaryCondition*>(bc);
        if (c == nullptr)
            continue;
        if (c->getCreatedStep() == stepId)
            bdsToDelete.append(c);
    }
    for (FITKAbaAbstractBoundaryCondition* b : bdsToDelete)
    {
        this->removeDataObj(b);
    }
}

void Interface::FITKAbaBoundaryConditionManager::replaceStep(int oldStep, int newStep)
{
    int count = this->getDataCount();
    for (int i = 0; i < count; ++i)
    {
        FITKAbstractBC* bc = this->getDataByIndex(i);
        FITKAbaAbstractBoundaryCondition* condition = dynamic_cast<FITKAbaAbstractBoundaryCondition*>(bc);
        if (condition == nullptr)
            continue;
        if (condition->getCreatedStep() != oldStep)
            continue;
        condition->setCreatedStep(newStep);
        if (!condition->isValidInCreatedStep())
            condition->setActiveState(false);
    }
}
